package logic

import (
	"context"
	"gitee.com/zyw0605688_admin/gozero/organization/model"

	"gitee.com/zyw0605688_admin/gozero/organization/internal/svc"
	"gitee.com/zyw0605688_admin/gozero/organization/pb/organizationPb"

	"github.com/zeromicro/go-zero/core/logx"
)

type DepartmentCreateLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewDepartmentCreateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DepartmentCreateLogic {
	return &DepartmentCreateLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *DepartmentCreateLogic) DepartmentCreate(in *organizationPb.DepartmentCreateRequest) (*organizationPb.DepartmentCreateResponse, error) {
	item := model.Department{
		DepartmentName: in.DepartmentName,
		DepartmentCode: in.DepartmentCode,
		DepartmentDesc: in.DepartmentDesc,
	}
	err := l.svcCtx.Db.Save(&item).Error
	if err != nil {
		return nil, err
	}

	return &organizationPb.DepartmentCreateResponse{
		DepartmentId:   item.DepartmentId,
		DepartmentName: item.DepartmentName,
		DepartmentCode: item.DepartmentCode,
		DepartmentDesc: item.DepartmentDesc,
	}, nil
}
